package com.chen.demoresttemplate.controller;

import com.chen.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;

@RestController
@RequestMapping("/RestTemplateController")
public class DemoRestTemplate {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 服务降级
     */
    @RequestMapping("/test")
    public void test1(){
        String url = "http://feign-called/feigncalled/demo1"; //服务名 + 加请求地址
        String request="restTemplate";
        ResponseResult result = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<Object>(request, null), ResponseResult.class).getBody();
        System.out.println(result);

    }
}
